﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Xml.Serialization;
using System.Linq;
using System.Text;

namespace Bioinformatics.Types
{
    [Serializable]
    public class GeneticSequenceCollection : List<GeneticSequence>
    {
        //public Dictionary<char, float> StationaryProbabilities { get; private set; }
        //public Alphabet Alphabet { get; private set; }
        //Testpublic int SequenceLength { get; private set; }
        
        public static GeneticSequenceCollection ImportCollectionFromFile(string path)
        {
            try
            {
                var streamReader = new StreamReader(path);
                var xmlSerializer = new XmlSerializer(typeof(GeneticSequenceCollection));
                var importedGeneticSequenceCollection = (GeneticSequenceCollection)xmlSerializer.Deserialize(streamReader);
                streamReader.Close();
                return importedGeneticSequenceCollection;
            }
            catch (Exception exception)
            {
                return new GeneticSequenceCollection();
            }
        }

        public void ExportCollectionToFile(string path)
        {
            var streamWriter = new StreamWriter(path);
            var xmlSerializer = new XmlSerializer(typeof (GeneticSequenceCollection));
            xmlSerializer.Serialize(streamWriter, this);
            streamWriter.Close();
        }
    }
}
